package com.boy.commonutils.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;


@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        this.setFieldValByName("register", new Date(), metaObject);//创建修改时间
        this.setFieldValByName("start", new Date(), metaObject);//创建修改时间
        this.setFieldValByName("begin", new Date(), metaObject);//创建修改时间
        this.setFieldValByName("end", new Date(), metaObject);
        this.setFieldValByName("created", new Date(), metaObject);//创建修改时间
        this.setFieldValByName("updated", new Date(), metaObject);
        //this.setFieldValByName("id", new IdGenerator().next(), metaObject);//给id设置
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.setFieldValByName("updated", new Date(), metaObject);//修改时间
    }
}
